package threadcoreknowledge.createthread.stopthread;

/**
 * 正确的方法关闭线程，没有sleep
 */
public class RightWayStopThread implements Runnable {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new RightWayStopThread());
        thread.start();
        Thread.sleep(2000);
        thread.interrupt();
    }

    @Override
    public void run() {
        int num = 0;
        //当Interrupted=true时停止
        while (!Thread.currentThread().isInterrupted()&& num <= Integer.MAX_VALUE /2){
            if ((num % 10000 == 0)){
                System.out.println(num+"是10000的倍数");
            }
            num++;
        }
    }
}
